var Core = (function($) {
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1]:
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    if (Sys.ie) document.documentElement.addBehavior("#default#userdata");
    
    var Util = {
        Sys: {},
        submit: function(o) {
            if (typeof(o) != 'object') o = $(":submit");
            o.attr('disabled', 'disabled');
            return true;
        },
        rule: function(method, a) {
            switch (method) {
                case '*':
                    var r = /[\w\W]+/;
                    break;
                case 'key':
                    var r = /^([a-zA-Z0-9]|[._-]){2,32}$/;
                    break;
                case 'uname':
                    var r = /^([a-zA-Z0-9]|[_-]){5,50}$/;
                    break;
                case 'pwd':case 'password':
                    var r = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z\\W]{8,50}$/;
                    break;
                case 'mobile':
                    var r = /^1[3-9]{1}[\d]{9}$/;
                    break;
                case 'phone':
                    return (/^1[3-9]{1}[\d]{9}$/.test(a) || /^0[0-9]{2,3}(-)?[0-9]{7,8}$/.test(a));
                    break;
                case 'datetime':
                    var d = new Date(Date.parse(a.toString().replace(/-/g, "/"))); //"2005-12-15 09:41:30"
                    return /^[0-9]*[1-9][0-9]*$/.test(d.getFullYear());
                    break;
                case 'int':
                    var r = /^-?\d+$/;
                    break; //正-负整数+0
                case 'intp':
                    var r = /^[0-9]*[1-9][0-9]*$/;
                    break; //正整数
                case 'intps':
                    var r = /^\d+$/;
                    break; //正整数+0
                case 'intn':
                    var r = /^-[0-9]*[1-9][0-9]*$/;
                    break; //负整数
                case 'intns':
                    var r = /^((-\d+)|(0+))$/;
                    break; //负整数+0
                case 'dbl':
                case 'float':
                    var r = /^(-?\d+)(\.\d+)?$/;
                    break; //浮点数
                case 'dblp':
                    var r = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
                    break; //正浮点数
                case 'dblps':
                    var r = /^\d+(\.\d+)?$/;
                    break; //正浮点数 + 0
                case 'dbln':
                    var r = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
                    break; //负浮点数
                case 'dbls':
                    var r = /^((-\d+(\.\d+)?)|(0+(\.0+)?))$/;
                    break; //负浮点数 + 0
                case 'boolean':
                    var r = /^[0-1]{1}$/;
                    break; //0|1 布尔值
                case 'booleans':
                    var r = /^[1-2]{1}$/;
                    break; //1|2 布尔值
                case 'numeric':
                    var r = /^[0-9]*$/;
                    break;
                case 'money':
                    var r = /^([1-9][\d]{0,9}|0)(\.[\d]{1,2})?$/;
                    break;
                default:
                    var r = /^[+\-]?\d+(\.\d+)?$/;
                    break;
            }
            return r.test(a);
        },
        isUndefined: function(v){
            return (typeof v === "undefined")? true: false;
        },
        isEmpty: function(v){
            return ($.trim(v) == "")? true: false;
        },
        saveUserdata: function(name, data) {
            /**
             * set本地存储的变量
             */
            if (Sys.ie) {
                if (data.length < 54889) {
                    with(document.documentElement) {
                        setAttribute("value", data);
                        save('Dv__' + name);
                    }
                }
            } else if (window.localStorage) {
                localStorage.setItem('Dv__' + name, data);
            } else if (window.sessionStorage) {
                sessionStorage.setItem('Dv__' + name, data);
            }
        },
        loadUserdata: function(name) {
            /**
             * get本地存储的变量
             */
            if (Sys.ie) {
                with(document.documentElement) { load('Dv__' + name); return getAttribute("value"); }
            } else if (window.localStorage) {
                return localStorage.getItem('Dv__' + name);
            } else if (window.sessionStorage) {
                return sessionStorage.getItem('Dv__' + name);
            }
        },
        delUserdata: function(name) {
            /**
             * 删除本地存储的变量
             */
            if (Sys.ie) {
                with(document.documentElement) {
                    removeAttribute('value');
                    save('Dv__' + name);
                }
            } else if (window.localStorage) {
                localStorage.removeItem('Dv__' + name);
            } else if (window.sessionStorage) {
                sessionStorage.removeItem('Dv__' + name);
            }
            return true;
        },
        Easyui: {
            defaults: {
                width: "auto",
                height: 'auto',
                rownumbers: true,
                striped: true,
                idField: "id",
                method: "get",
                url: "",
                loadMsg: "数据加载中，请稍候...",
                autoRowHeight: false,
                // rowStyler: function(index,row){return 'height:26px;';},
                singleSelect: false,
                checkOnSelect: true,
                fitColumns: false,
                remoteSort: true,
                multiSort: false,
                pagination: true,
                pageSize: 100,
                pageList: [50, 100, 200],
                columns: [],
                frozenColumns: [],
                onBeforeLoad: function (param){},
                onClickRow: function (index,row){},
                onDblClickRow: function (index,row){},
                onLoadSuccess: function (data){},
                onSortColumn: function (sort, order){},
            },
            init: function(obj, options, searchbar){
                // console.log(this); //Util.Easyui
                var _this = this;
                var $dom = obj;
                var $box = $dom.parents().eq(0);
                var $form = searchbar;
                var opts = $.extend({}, Util.Easyui.defaults, options);
                $.data($dom[0],"a-parms",{});
                opts.onBeforeLoad = function(param){
                    $.data($dom[0],"a-parms",param);
                    return true;
                }
                
                var resizeArr = [];
                isNaN(Number(opts.width)) && resizeArr.push('width');
                isNaN(Number(opts.height)) && resizeArr.push('height');
                $box.data("resize-edge", resizeArr).attr("resizeable","1");
                opts.width = $.inArray('width', resizeArr)>-1? $box.width(): opts.width;
                opts.height = $.inArray('height', resizeArr)>-1? ($(window).height()-$box.offset().top): opts.height;
                window.gridDom = $dom;

                var newCols = _this.setColumns($.extend(true,{},opts.columns), opts.width);
                opts.columns = newCols;

                if(!Util.isUndefined($form)){
                    _this.bindSearch($dom, $form);
                }
                
                easyloader.locale = 'zh_CN';
                easyloader.theme = 'material-teal';
                easyloader.load('datagrid', function() {
                    $dom.datagrid(opts);
                    _this.resize($dom, $box);
                });
            },
            setColumns: function(_mycols, _width){
                var w = _width - 30;
                var cols_a = [];
                var mycols = _mycols[0];
                for(var i=0;i<mycols.length;i++){
                    if(Util.isUndefined(mycols[i].hidden) && !Util.isUndefined(mycols[i].width) && mycols[i].width>0){
                        w -= mycols[i].width;
                    }
                    if(Util.isUndefined(mycols[i].width)){
                        cols_a.push(i);
                    }
                }
                if(w>0){
                    for(var j=0;j<cols_a.length;j++){
                        mycols[cols_a[j]].width = parseInt(w/cols_a.length);
                    }
                }
                return _mycols;
            },
            resize: function($dom, $box){
                $box.bind('_resize',function(){
                    var arr = $box.data("resize-edge");
                    var r = {};
                    $.inArray('width', arr)>-1 && (r.width = $box.width());
                    $.inArray('height', arr)>-1 && (r.height = ($(window).height()-$box.offset().top));
                    if($dom && typeof $dom.datagrid =='function'){
                        $dom.datagrid("resize", r);
                    }else if(window.gridDom && typeof window.gridDom.datagrid =='function'){
                        window.gridDom.datagrid("resize", r);
                    }
                });
                $box.triggerHandler('_resize');
            },
            bindSearch: function($dom, $form){
                var _this = this;
                /**切换过滤条件弹出层显示隐藏 */
                if($('.switch_search').length>0 && $('.switch_search').hasClass('filter')){
                    if($form.parents('.search_wraper').length>0){
                        var _s_wraper = $form.parents('.search_wraper');
                        $('.switch_search,.search_wraper_close,.search_close').off('click').on('click', function(e) {
                            e.preventDefault();
                            var _f_h = _s_wraper.height();
                            _s_wraper.toggleClass('open');
                            if(_s_wraper.hasClass('open')){
                                _s_wraper.css('height', _f_h+'px');
                                $form.find('button[b-type="radius"],a[b-type="radius"]').hide();
                            }else{
                                _s_wraper.css('height', 'auto');
                                $form.find('button[b-type="radius"],a[b-type="radius"]').show();
                            }
                            $('.table_box[resizeable="1"]').triggerHandler('_resize');
                        })
                    }
                }
                /**点击取消时关闭过滤条件弹出层 */
                // $form.find('button[role="btn-cancel"]').off('click').on('click', function() {
                //     $form.parents('.search_wraper').removeClass('open');
                // })
                //重置按钮
                $form.find('button[role="btn-cancel"]').off('click').on('click', function() {
                    $form.find('.row[row-name]').each(function(){
                        var _row = $(this);
                        Util.Search.resetFilter(_row);
                    })
                })
                $form.find('.search-btn').off('click').on('click', function(event, isdel) {
                    event.preventDefault();
                    $('body').find('.zs-box,.select-defined').removeClass('active');
                    if(Util.isUndefined($(this).attr("unclick"))){
                        $(this).attr("unclick","true");
                        if($(this).attr('attr-define')!='true'){
                            $dom.datagrid('clearChecked');
                            $dom.datagrid('clearSelections');
                        }
                        var parmAry = $form.serializeArray();
                        var parm = {};
                        $.each(parmAry, function(index, item) {
                            if((item.value + '')!= ''){
                                if(parm[item.name]!='' && typeof parm[item.name] != "undefined"){
                                    /**checkbox多选项时 */
                                    parm[item.name] += ','+item.value;
                                }else{
                                    parm[item.name] = item.value;
                                }
                            }
                        });
                        for(var key in parm){
                            if(key.indexOf('[0]')>0 || key.indexOf('[1]')>0){
                                var tkey = key.substr(0, key.length - 3);
                                if(key.indexOf('[0]')>0){
                                    parm[tkey] = parm[key] + ','+(typeof parm[tkey+'[1]']!='undefined'?parm[tkey+'[1]']:'');
                                    delete parm[tkey+'[1]'];
                                }else{
                                    parm[tkey] = (typeof parm[tkey+'[0]']!='undefined'?parm[tkey+'[0]']:'')+ ','+parm[key];
                                    delete parm[tkey+'[0]'];
                                }
                                delete parm[key];
                                continue;
                            }
                        }
                        var oparms = $.extend({}, {}, parm);
                        for(var key in parm){
                            if(parm[key].indexOf('allckeds')>-1){
                                var r_a = parm[key].split(',');
                                r_a.splice(parm[key].indexOf('allckeds'), 1);
                                parm[key] = r_a.join(',');
                                // delete parm[key];
                                continue;
                            }
                        }
                        
                        /**关闭过滤条件弹出层 */
                        if($form.parents('.search_wraper').length>0){
                            $form.parents('.search_wraper').removeClass('open');
                            $form.parents('.search_wraper').css('height', 'auto');
                            $form.find('button[b-type="radius"],a[b-type="radius"]').show();
                            $('.table_box[resizeable="1"]').triggerHandler('_resize');
                        }
                        _this.search($dom, parm);
                        $(this).removeAttr("unclick");

                        if(typeof isdel == 'undefined'){
                            /**不是删除条件时触发的被动搜索 即用户主动搜索 清除dtype和mydatetime的data-isdeleted值*/
                            $form.find('.row[row-name="dtype"]').removeData('isdeleted');
                            $form.find('.row[row-name="mydatetime"]').removeData('isdeleted');
                        }
                        Util.Search.onSearchHandle($form, oparms, isdel);
                    }
                    return false;
                })
            },
            search: function($dom, parms){
                $.data($dom[0],"a-parms",parms);
                $dom.trigger('search-start', parms);
                if ($dom.attr('data-preve-load') !== 'yes') {
                    $dom.datagrid('load', parms);
                }
            }
        },
        Search: {
            resetFilter: function(_row){
                /**search row 逐行重置搜索数据  */
                if(_row.attr('row-name') == 'dtype'){
                    _row.find("select.dtype").setZsValue(_row.find("select.dtype").attr('defaultv'));
                    _row.find('div[date-dtype="dtype"]').find('input.date-ico').each(function(idx,itm){
                        var _md = $(itm).attr('defaultv');
                        $(itm)[0].defaultValue = _md;
                    })
                }else if(_row.attr('row-name') == 'mydatetime'){
                    _row.find('input.date-ico').each(function(idx,itm){
                        var _md = $(itm).attr('defaultv');
                        $(itm)[0].defaultValue = _md;
                    })
                }else if(_row.find('.z-select').length>0){
                    _row.find('.z-select').setZsValue('');
                }else if(_row.find('.zs-select-group').length>0){
                    _row.find('.zs-select-group').clearGroupVal('');
                }
            },
            searchArray: function(){
                var f = [];
                var aColumn = Core.Easyui.FrozenColumn || [];
                var bColumn = Core.Easyui.FieldColumn || [];
                aColumn.map(function(a){
                    if(a.search){
                        f.push({
                            checked: a.nowsearch? true: false,
                            inlined: a.nowsearch? true: false,
                            name: a.field,
                            title: a.title,
                            alias: a.alias? a.alias: false,
                            type: a.searchtype? a.searchtype: 'input'
                        })
                    }
                }),
                bColumn.map(function(b){
                    if(b.search){
                        f.push({
                            checked: b.nowsearch? true: false,
                            inlined: b.nowsearch? true: false,
                            name: b.field,
                            title: b.title,
                            alias: b.alias? b.alias: false,
                            type: b.searchtype? b.searchtype: 'input'
                        })
                    }
                })
                return f;
            },
            typeList: function(){
                var t = {'input':[],'select':[],'checkbox':[],'radio':[],'date':[]};
                var arr = Table_Filters || Core.Search.searchArray();
                arr.map(function(x){
                    t[x.type].push(x.alias || x.name);
                })
                return t;
            },
            onSearchHandle: function(_form, _parm, isdel){
                if($('.search_filter').length>0){
                    _form.data('filterdatas',_parm);
                    Util.Search.setFiltersRow(isdel);
                }else{
                    if(_form.parents('.search_wraper').length>0){
                        var _s_w = _form.parents('.search_wraper');
                        _s_w.after('<div class="search_filter disn">\
                            <div class="s_filter_left">\
                                <div class="s_filter_inner">\
                                    <i class="s_filter-icon icon-s-filter"></i>\
                                    <ul class="now-filter-item">\
                                    </ul>\
                                </div>\
                            </div>\
                            <div class="s_filter_right"><i class="icon-delete-all"></i></div>\
                        </div>');
                        _form.data('filterdatas', _parm);
                        Util.Search.setFiltersRow(isdel);
                    }
                }
            },
            initFilter: function(rsourceUrl, rUrl, sUrl){ 
                var _this = this;
                seriesUrl = (typeof sUrl != 'undefined')? sUrl:'';
                regionUrl = (typeof rUrl != 'undefined')? rUrl:'';
                // if(!Table_Filters || Table_Filters.length == 0){ return false;}
                /*被勾选字段 存为数组*/
                var fiterChecked = [];
                for (var i in Table_Filters){
                    var _n = Table_Filters[i];
                    if(_n.alias){_n.name = _n.alias;}
                    fiterChecked.push(_n);
                }
                var skeys = $(".search_form").find('.condition').find('.row[row-name="dtype"]').length>0?['dtype']:[];
                fiterChecked.map(function(r){
                    /**selfdefine为true 为自定义 */
                    if(!r.selfdefine && (filterType['select'].indexOf(r.name)>-1 || filterType['checkbox'].indexOf(r.name)>-1 || filterType['radio'].indexOf(r.name)>-1)){ 
                        skeys.push(r.name);
                    }
                    return r;
                });
                var rdata = {};
                if(skeys.length>0){
                    //ajax获取搜索字段基础数据
                    $.get(rsourceUrl+"?r="+Math.random(),{skeys: skeys.join(',')},function(data){
                        if(data){ 
                            rdata = data;
                        }
                        _this.renderSearch(rdata, fiterChecked);
                    },"json");
                }else{
                    _this.renderSearch(rdata, fiterChecked);
                }
                if(!$('body').hasClass('full')){
                    $('body').addClass('full');
                }
                // console.log(skeys,"==skeys");
                // var rdata = {};
                // if(skeys.length>0){ 
                //     rdata = {
                //         "dtype":[{"id":1,"title":"按月份","ckey":"month"},{"id":2,"title":"按日期","ckey":"day"}],
                //         "infotype":[{"id":7,"title":"二网"},{"id":8,"title":"展厅"},{"id":9,"title":"网电销"}],
                //         "infoplace":[{"id":8,"title":"自然到店"},{"id":9,"title":"广告投放"},{"id":10,"title":"车展\/外拓"},{"id":11,"title":"主机厂"}],
                //         "infosource":[{"id":12,"title":"未知"},{"id":13,"title":"汽车之家"},{"id":14,"title":"易车网"},{"id":15,"title":"太平洋汽车网"},{"id":16,"title":"懂车帝"},{"id":17,"title":"17网"},{"id":18,"title":"爱卡汽车网"}],
                //         "dealer":[{"id":1001,"title":"南京长马"},{"id":1002,"title":"杭州长马"}]};
                //     _this.renderSearch(rdata, fiterChecked);
                // }else{
                //     _this.renderSearch(rdata, fiterChecked);
                // }
            },
            renderSearch: function(rdata, fiterChecked) {
                /*渲染显示被选中筛选的字段*/
                var _list = $(".search_form").find('.condition');
                _list.data('condition',rdata);
                Core.Search.removeRows(_list, fiterChecked);
                for(var i=0; i<fiterChecked.length; i++){
                    var _name = fiterChecked[i].name;
                    var _title = fiterChecked[i].title;
                    if(_list.find('.row[row-name="'+_name+'"]').length>0){ continue;} /*某个条件已存在search_form中时 跳过*/
                    var _str = '';
                    _str +='<div class="row'+(fiterChecked[i].inlined?' inline-row':'')+(fiterChecked[i].selfdefine?' check_defined':'')+'" row-name="'+_name+'">\
                                <div class="field_text">'+_title+'：<a class="filter-close-s" tag="'+_name+'" href="javascript:;"></a></div>';
                    if(filterType['select'].indexOf(_name)>-1){
                        if(_name == 'region'){
                            _str +='<select relative-parent="window" class="zs-select-group oselectregion" name="'+_name+'" data-title="省份,城市" data-holder="请选择省份/城市" data-skin="select-blue"></select>';
                        }else{
                            _str +='<select relative-parent="window" class="z-select '+_name+'"'+(['dealer','dealerauth'].indexOf(_name)>-1?' data-content="true"':'')+' name="'+_name+'"><option value="">请选择</option>';
                            if(rdata[_name]){
                                rdata[_name].map(function(r){
                                    _str +='<option value="'+r.id+'">'+r.title+'</option>';
                                })
                            }
                            _str +='</select>';
                        }
                    }else if(filterType['checkbox'].indexOf(_name)>-1 || filterType['radio'].indexOf(_name)>-1){
                        _str +='<div class="labelrow"'+(fiterChecked[i]['selfdefine']? ' def-row="'+_name+'" style="padding-right:5px;"':'')+'>';
                        if(rdata[_name]){
                            /*if(fiterChecked[i]['needall']){*/
                            if(filterType['checkbox'].indexOf(_name)>-1){
                                /**去掉needall的参数判断，在所有checkbox多选框的地方都加“全部”选择 */
                                _str +='<label class="l-checkbox allchecked"><input type="checkbox" name="'+_name+'" value="allckeds" />';
                                _str +='<i></i><span>全部</span></label>';
                            }
                            rdata[_name].map(function(r){
                                if(filterType['checkbox'].indexOf(_name)>-1){
                                    _str +='<label class="l-checkbox"><input type="checkbox" name="'+_name+'" value="'+r.id+'" />';
                                }else{
                                    _str +='<label class="l-radio"><input type="radio" name="'+_name+'" value="'+r.id+'" />';
                                }
                                _str +='<i></i><span>'+r.title+'</span></label>';
                            });
                        }
                        _str +='</div>';
                    }else if(filterType['date'].indexOf(_name)>-1){
                        _str +='<input type="text" name="'+_name+'[0]" id="'+_name+'0" data-options="seconds:true,maxDate:'+_name+'1" class="input-text date-ico" readonly value="" placeholder="请选择开始时间" />\
                                <span class="form-to">-</span> <input type="text" name="'+_name+'[1]" id="'+_name+'1" data-options="seconds:true,minDate:'+_name+'0" class="input-text date-ico" readonly value="" placeholder="请选择结束时间" />';
                    }else{
                        _str +='<input type="text" name="'+_name+'" class="input-text" placeholder="请输入'+_title+'" autocomplete="off" />';
                    }
                    _str += (fiterChecked[i]['selfdefine']?'<a class="check_defined_btn" def-type="'+_name+'"'+(fiterChecked[i]['defineUrl']?' def-url="'+fiterChecked[i]['defineUrl']+'"':'')+'>自定义</a>':'')+'</div>';
                    if(!i){_list.append(_str);continue;}
                    _list.find('.row[row-name="'+fiterChecked[i-1].name+'"]').after(_str);
                }
                // _list.append('<div class="more_search"><a class="add_more_fitlers"><i class="icon-more-filter"></i>更多条件</a></div>');
                Core.Search.initEvent();
            },
            setFiltersRow: function(isdel){
                var _this = this;
                var $form = $(".search_form");
                var _filter_datas = $form.data('filterdatas');
                var _Actually = [];
                var _ssstr = '';
                for(var _name in _filter_datas){
                    if(_filter_datas[_name]!=''){
                        //title
                        var name = _name.indexOf('[0]')>0? _name.split('[0]')[0]:(_name.indexOf('[1]')>0? _name.split('[1]')[0]:_name); 
                        var title = $form.find('.row[row-name="'+name+'"]').find('.field_text').text();
                        var text = _filter_datas[_name];
                        if(['stime','etime'].indexOf(_name)>-1){
                            if(typeof _filter_datas['dtype']!='undefined' || _name == 'etime'){
                                continue;
                            }else{
                                name = 'mydatetime';
                                title = $form.find('.row[row-name="mydatetime"]').find('.field_text').text();
                                var t1 = '';var t2 = '';
                                    t1 = $form.find('.row[row-name="mydatetime"]').find('input[name="stime"]').val();
                                    t2 = $form.find('.row[row-name="mydatetime"]').find('input[name="etime"]').val();
                                text = ' '+t1 +' 至 '+ t2;
                            }
                        }
                        if(name == 'dtype'){
                            text = $form.find('.row[row-name="'+name+'"]').find('.zs-value').text();
                            var t1 = '';var t2 = '';
                                t1 = $form.find('.row[row-name="'+name+'"]').find('input[name="stime"]').val();
                                t2 = $form.find('.row[row-name="'+name+'"]').find('input[name="etime"]').val();
                            text += ' '+t1 +' 至 '+ t2;
                        }
                        //text
                        if(filterType['select'].indexOf(_name)>-1){
                            if(_name == 'region'){
                                text = $form.find('.row[row-name="'+name+'"]').find('select').oGetSelectText();
                            }else{
                                text = $form.find('.row[row-name="'+name+'"]').find('.zs-value').text();
                            }
                        }else if(filterType['checkbox'].indexOf(_name)>-1){
                            text = $form.find('.row[row-name="'+name+'"]').find('input[name="'+name+'"]:checked').map(function(){
                                return $(this).parents('.l-checkbox').find('span').text();
                            }).get().join("/");
                        }else if(filterType['radio'].indexOf(_name)>-1){
                            text = $form.find('.row[row-name="'+name+'"]').find('input[name="'+name+'"]:checked').parents('.l-radio').find('span').text();
                        }else if(filterType['date'].indexOf(name)>-1){
                            var time1 = '';var time2 = '';
                            time1 = $form.find('.row[row-name="'+name+'"]').find('input[name="'+name+'[0]"]').val();
                            time2 = $form.find('.row[row-name="'+name+'"]').find('input[name="'+name+'[1]"]').val();
                            text = time1 +' 至 '+ time2;
                        }
                        var has = false;
                        for(var i=0;i<_Actually.length;i++){
                            if(name == _Actually[i].name){
                                has = true;
                            }
                        }
                        if(!has){
                            if((name == 'dtype' || name == 'mydatetime') && typeof isdel!='undefined'){
                                /**从delFilter方法中触发删除 需要判断dtype 或 mydatetime是否被删除 如果已删除则不再显示*/
                                if($form.find('.row[row-name="'+name+'"]').data('isdeleted')){
                                    continue;
                                }
                            }
                            /*_Actually数组存放条件name title和text文本*/
                            _Actually.push({name: name, title: title, text: text});
                            _ssstr += '<li class="filter-item">\
                                <span class="lfilter-cell">\
                                    <span class="cell-key">'+title+'</span>\
                                    <span class="cell-val">'+text+'</span>\
                                </span>\
                                <i class="icon-del" del-tag="'+name+'"></i>\
                            </li>';
                        }
                    }
                }
                $('.search_filter').find('.now-filter-item').html(_ssstr);
                _Actually.length>0? $('.search_filter').removeClass('disn'): $('.search_filter').addClass('disn');
                $('.table_box').triggerHandler('_resize');
                /*icon-del被点击时清除筛选条件*/
                $('.search_filter').find('.icon-del').off('click').on('click',function(){
                    _this.delFilter($form, $(this).attr('del-tag'));
                    $form.find('.search-btn').trigger('click', 1);
                })
                // $('.search_filter').find('.lfilter-cell').off('click').on('click',function(){
                //     $form.parents('.search_wraper').addClass('open');
                // })
                // delAllFilter
                $('.search_filter').find('.icon-delete-all').off('click').on('click',function(){
                    Core.Search.delAllFilter();
                })
            },
            delFilter: function(_form, _v_name){
                var _row = _form.find('.row[row-name="'+_v_name+'"]');
                if(_v_name == 'dtype' || _v_name == 'mydatetime'){
                    _row.data('isdeleted', true);
                    this.resetFilter(_row);
                }else{
                    if(filterType['input'].indexOf(_v_name)>-1){
                        _row.find('input[name="'+_v_name+'"]').val('');
                    }
                    if(filterType['checkbox'].indexOf(_v_name)>-1){
                        _row.find('input[type="checkbox"]').each(function () {
                            $(this).removeAttr("checked", "checked");
                        });
                    }
                    if(filterType['radio'].indexOf(_v_name)>-1){
                        _row.find('input[type="radio"]').each(function () {
                            $(this).removeAttr("checked", "checked");
                        });
                    }
                    if(filterType['date'].indexOf(_v_name)>-1){
                        _row.find('input[name="'+_v_name+'[0]"]').val('');
                        _row.find('input[name="'+_v_name+'[1]"]').val('');
                    }
                    if(filterType['select'].indexOf(_v_name)>-1){
                        if(_v_name == 'region'){
                            _row.find('select').clearGroupVal();
                        }else{
                            _row.find('.z-select').setZsValue('');
                        }
                    }
                }
            },
            delAllFilter: function(){
                var _this = this;
                var $form = $(".search_form");
                $('.search_filter').addClass('disn');
                $('.search_filter').find('.icon-del').each(function(){
                    _this.delFilter($form, $(this).attr('del-tag'));
                })
                $form.find('.search-btn').trigger('click', 1);
            },
            removeRows: function(_list, fiterChecked){
                /*从search_form中删除没有选中的条件*/
                _list.find('.more_search').remove();
                _list.find('.row[row-name]').each(function(){
                    var _t = $(this);
                    if(_t.find('.filter-close-s').length == 0){return true;}
                    var _isNeed = false;
                    for(var j=0;j<fiterChecked.length;j++){
                        if(fiterChecked[j].name == _t.attr('row-name')){
                            _isNeed = true;
                        }
                    }
                    if(!_isNeed){_t.remove();}
                })
            },
            initEvent: function(){
                var _thisFun = this;
                var $form = $(".search_form");
                $form.find('select.z-select').zSelect();
                /*筛选条件弹出层 每行关闭*/
                $form.find('.filter-close-s').off('click').on('click',function(){
                    var _t = $(this);
                    var _tag = _t.attr('tag');
                    for (var i in Table_Filters){
                        var _alias = Table_Filters[i].alias || Table_Filters[i].name;
                        if(_tag.indexOf(_alias)>-1){
                            Table_Filters[i].checked = 'false';
                            _t.parents('.row').remove();
                            break;
                        }
                    }
                });
                /*点击弹出选中条件*/
                $form.find('.add_more_fitlers').off('click').on('click',function(){
                    Core.Dialog.open({
                        'title': '选择条件',
                        'width': '590px',
                        'height': '450px',
                        'shade': '0',
                        'url': '../dialog/dialog_filter.html'
                    });
                })
                /**初始化ajax下拉列表 */
                if(seriesUrl){
                    $form.find("select.series").zsLoadData({
                        'valueField': 'id',
                        'textField': 'title',
                        'url': seriesUrl,
                    });
                }
                if(regionUrl){

                }
                if($form.find("select.dtype").length>0){
                    var _cdtion = $form.find('.condition').data('condition');
                    var _dtype_cdtion = [];
                    if(_cdtion){
                        _dtype_cdtion = _cdtion['dtype'];
                    }
                    var f_get_key_type =  function(kid){
                        var _k_t = _dtype_cdtion[0].ckey;
                        for(var i=0;i<_dtype_cdtion.length;i++){
                            if(_dtype_cdtion[i].id == kid){
                                _k_t = _dtype_cdtion[i].ckey;
                                break;
                            }
                        }
                        return _k_t;
                    }

                    /**SearchDtype为外部定义默认搜索按月或按日 */
                    var oldkey = $form.find("select.dtype").getZsValue();
                    oldkey = !oldkey? ((typeof SearchDtype!='undefined')? SearchDtype: _dtype_cdtion[0].id): oldkey;
                    var _key_type = f_get_key_type(oldkey); /**分析报表 日报月报默认按*查询 */
                    
                    function setdatetimev(_k_t){
                        $form.find('div[date-dtype="dtype"]').find('input.date-ico').each(function(idx,itm){
                            var _time = new Date(), _y = _time.getFullYear(),_m = _time.getMonth() - (-1),_d = _time.getDate();
                            var _datev = $(this).val();
                            if(_datev == ''){
                                _datev = _y+'-'+_m+(_k_t == 'day'?('-'+(idx == 0?'01':_d)):'');
                                $(itm).attr('defaultv',_datev);
                            }else{
                                var carry = _datev.split('-');
                                _datev = (carry.length>2)? carry.slice(0,2).join('-'): (_datev+'-'+(idx == 0?'01':_d));
                            }
                            $(itm).attr({
                                'name': idx == 0?'stime':'etime',
                                'date-type': _k_t
                            }).val(_datev);
                        })
                    }
                    $form.find("select.dtype").off('setZsValue').on('setZsValue',function(){
                        var _key = $(this).getZsValue();
                        if(oldkey == _key){ return false;}
                        _key_type = f_get_key_type(_key);
                        oldkey = _key;
                        setdatetimev(_key_type);
                    });
                    if(!$form.find("select.dtype").getZsValue()){
                        $form.find("select.dtype").zsSetData(_dtype_cdtion,{
                            valueField: 'id',
                            textField: 'title'
                        }).setZsValue(oldkey).attr('defaultv', oldkey);
                        setdatetimev(_key_type);
                    }
                }
                if($form.find('.row.inline-row').length>0){
                    /**搜索和展开搜索条件按钮的显示 */
                    var _n = $form.find('.row.inline-row').length;
                    $form.find('.row.form-footer-bar').find('button[r-button]').each(function(){
                        var _b = $(this);
                        $form.find('.row.inline-row').eq(_n-1).append(_b.clone(true).attr('b-type','radius').show());
                    })
                }
                function resizelabelrow(){
                    /**切换多选项元素块收起和打开 */
                    $('.labelrow').each(function(idx,itm){
                        var v = $(itm).parents('.row'); if(v.hasClass('check_defined')){return true;}
                        if(v.find('.morebtn').length == 0){
                            if(v.outerHeight()>51){
                                v.addClass('hasmorebtn').addClass('slidehide').append('<a class="morebtn">更多</a>');
                                $('.hasmorebtn').find('.morebtn').off('click').on('click',function(){
                                    var _ttp = $(this).parents('.hasmorebtn');
                                    _ttp.toggleClass('slidehide');
                                    $(this).text(_ttp.hasClass('slidehide')?'更多':'收起');
                                })
                            }
                        }else{
                            var _lh = v.find('.labelrow').outerHeight();
                            if(_lh<=30){
                                v.removeClass('hasmorebtn').removeClass('slidehide').find('.morebtn').off('click').remove();
                            }
                        }
                    })
                }
                if($('.labelrow').length>0){
                    resizelabelrow();
                    $(window).on('resize', function() {
                        resizelabelrow();
                    });
                    /**全选切换 */
                    $('.labelrow').find('input[type="checkbox"]').on('change',function(){
                        var _ts = $(this);
                        var pl = _ts.parents('.labelrow');
                        if(_ts.prop('checked')){
                            if(_ts.parents('.l-checkbox').hasClass('allchecked')){
                                pl.find('.l-checkbox:not(.allchecked)').find('input[type="checkbox"]').each(function(){
                                    $(this).prop("checked", true);
                                });
                            }else{
                                pl.find('.l-checkbox.allchecked').find('input[type="checkbox"]').prop("checked", false);
                            }
                        }else{
                            if(_ts.parents('.l-checkbox').hasClass('allchecked')){
                                pl.find('.l-checkbox:not(.allchecked)').find('input[type="checkbox"]').each(function(){
                                    $(this).prop("checked", false);
                                });
                            }else{
                                pl.find('.l-checkbox.allchecked').find('input[type="checkbox"]').prop("checked", false);
                            }
                        }
                    })
                }
                if($('.check_defined_btn').length>0){
                    $('.check_defined_btn').on('click',function(){
                        var _def_url = $(this).attr('def-url');
                        var _txt = $(this).parents('.row').find('.field_text').text();
                        _thisFun.defineCheckedFun(_txt,_def_url);
                    });
                }
                if($('.table_box[resizeable="1"]').length>0){
                    $('.table_box[resizeable="1"]').triggerHandler('_resize');
                }
            },
            defineCheckedFun: function(txt, durl){
                Util.Dialog.open({
                    'father': 'top',
                    'framer': 'true',
                    'title': '自定义'+txt,
                    'width': '900px',
                    'height': '550px',
                    'url': durl+"?r="+Math.random()
                });
            },
            defineChecked: {
                add : function(defType, id, title) {
                    var _thisf = this;
                    if ($('.labelrow[def-row="'+defType+'"] :checkbox[name="'+defType+'"][value="'+id+'"]').length >=1) return;
                    var _s = '<label class="l-checkbox"><input type="checkbox" name="'+defType+'" checked value="'+id+'" /><i></i><span>'+title+'</span></label>';
                    $('.labelrow[def-row="'+defType+'"]').append(_s);
                    $('.labelrow[def-row="'+defType+'"]').find('input[type="checkbox"]').on('change',function(){
                        var _ts = $(this);
                        var pl = _ts.parents('.labelrow');
                        if(!_ts.prop('checked')){
                            _thisf.remove(pl.attr('def-row'), _ts.val());
                        }
                    })
                    return;
                },
                remove : function(defType, id) {
                    if (!$('.labelrow[def-row="'+defType+'"] :checkbox[name="'+defType+'"][value="'+id+'"]').length) return;
                    $('.labelrow[def-row="'+defType+'"] :checkbox[name="'+defType+'"][value="'+id+'"]').parent('label').remove();
                },
                getIds : function(defType) {
                    var o = $('.labelrow[def-row="'+defType+'"] :checkbox');
                    var ids = [];
                    if (!o.length) return ids;
                    for(var i = 0;i<o.length;i++){
                        var id = $(o[i]).val();
                        if (!Core.rule('intp',id)) continue;
                        ids.push(id);
                    }
                    return ids;
                }
            }
        },
        Dialog:{
			config: {
				shade: 0.3,
				area: ['40%','30%']
            },
            close: function(d,top){
                if(typeof top !="undefined" && top == "1"){
                    window.parent.layer.close(d);
                }else{
                    layer.close(d);
                }
            },
            loading: function(top){
                if(typeof top !="undefined" && top == "1"){
                    return window.parent.layer.load(1, {
                        shade: [0.3,'#000000']
                    });
                }else{
                    return layer.load(1, {
                        shade: [0.3,'#000000']
                    });
                }
            },
			confirm: function(opts){
				var tit = opts.title || '询问框', content = opts.content || '';
				return layer.ready(function(){
					var c_layer = layer.confirm('<div style="font-size:12px;">'+content+'</div>', {
						title: tit,
						btn: ['确定','取消'] //按钮
					}, function(){
						opts.ok && opts.ok(function(){
							layer.close(c_layer);
						});
					}, function(){
						opts.cancel && opts.cancel();
					});
				});
			},
			note: function(opts){
                var _shade = opts.shade || this.config.shade;
				var tit = opts.title || '提示', content = opts.content || '';
				var cbk = opts.callback || function(){};
				return layer.ready(function(){
					var l_tip = layer.alert('<div style="font-size:12px;">'+content+'</div>', {
						title: tit,
						shade: _shade
					}, function(){
						layer.close(l_tip);
						cbk && cbk();
					});
				});
			},
			msg: function(str){
				return layer.ready(function(){
					layer.msg(str,{timer:1500});
				});
			},
			open: function(opts){
				var _shade = opts.shade || this.config.shade;
				var tit = opts.title || '信息', url = opts.url || false;
				var w = opts.width || '580px', h = opts.height || '450px';
				var cont = opts.content || '';

				if(!url && cont==''){return};

				var isOpenInParent = (opts.father == 'top')? true: false;
				layer.ready(function(){
                    function initselect(s){
                        if(s.find('select.z-select')){
                            s.find('select.z-select').zSelect();
                        }
                    }
					function openly(htmls){
						if(isOpenInParent){
							return window.parent.layer.open({
								type: 1,
								title: tit,
								area: [w, h],
								shade: _shade,
                                content: htmls,
                                success: function(layero, index){
                                    initselect(layero);
                                }
							});
						}else{
							return layer.open({
								type: 1,
								title: tit,
								area: [w, h],
								shade: _shade,
								content: htmls,
                                success: function(layero, index){
                                    initselect(layero);
                                }
							});
						}
					}
					if(eval(opts.framer) && isOpenInParent){
						//iframe in parent window
						return window.parent.layer.open({
							type: 2,
							title: tit,
							area: [w, h],
							shade: _shade,
							content: url,
                            success: function(layero, index){
                                initselect(layero);
                            }
						});
					}
					if(eval(opts.framer) && !isOpenInParent){
						//iframe not in parent window
						return layer.open({
							type: 2,
							title: tit,
							area: [w, h],
							shade: _shade,
							content: url,
                            success: function(layero, index){
                                initselect(layero);
                            }
						});
					}
					if(!eval(opts.framer)){
						if(!url){
							openly(cont);
							return;
						}
						//normal
						$.get(url,function(_html){
							//normal
							openly(_html);
						})
					}
				});
			}
        },
        SlideDialog: {
            open: function(args, opencbk) {
                if (!args) { return false; }
                var x_body = args['depend'] ? (args['depend'].is('body') ? args['depend'] : args['depend'].parents('body')) : $('body');
                //已经有弹窗自定义窗口路由更换
                if (x_body.find('div[defineds]').length > 0) {
                    if (args['url'] && args['url'] != '') {
                        // console.log(x_body.find('div.my_define_dialog[defineds]').find('iframe.my_define_iframe'));
                        x_body.find('div.my_define_dialog[defineds]').find('iframe.my_define_iframe').attr('src', args['url']);
                    }
                    return false;
                }
                //生成元素
                var _def = 'my_define_';
                var _id = (Math.random() * 100).toFixed(0); //关联id
                var _index = (Math.random() * 1000).toFixed(0); //层高
                //遮罩
                var _shade = $('<div id="' + _def + 'shade_' + _id + '"></div>');
                _shade.addClass(_def + 'shade').css({
                    "z-index": _index,
                    "opacity": 0
                }).attr("defineds", _id);
                //容器
                var _box = $('<div id="' + _def + 'dialog_' + _id + '"></div>');
                _box.addClass(_def + 'dialog').css({
                    "width": args['area'] ? args['area'][0] : '600px',
                    "height": args['area'] ? args['area'][1] : '600px',
                    "z-index": _index - (-1)
                }).attr("defineds", _id);
                //title content
                if (args['title'] && args['title'] != '') {
                    var _tit = $('<div class="' + _def + 'title">' + args['title'] + '</div>');
                    _box.append(_tit)
                }
                var _con = $('<div class="' + _def + 'content"></div>');
                //iframe
                if (args['framer'] && args['url'] && args['url'] != '') {
                    var _iframe = $('<iframe scrolling="auto" allowtransparency="true" frameborder="0" src="' + args['url'] + '"></iframe>')
                    _iframe.addClass(_def + 'iframe');
                    _iframe.attr({
                        "id": _def + "iframe" + _id,
                        "name": _def + "iframe" + _id
                    })
                    _con.append(_iframe);
                }
                //close
                var _close = $('<a href="javascript:;" class="' + _def + 'close"></a>');
                _close.attr('attr-close', _id);
                _box.append(_con).append(_close);
                if (args['depend']) {
                    //弹出层的相对位置
                    _shade.css({
                        "height": "100%"
                    });
                    _box.css({
                        "height": "100%"
                    });
                }
                //从右侧滑出
                x_body.append(_shade).append(_box);
                var stv = setTimeout(function() {
                    x_body.find('.' + _def + 'dialog').addClass('from_right');
                    _shade.css("opacity", 0);
                    // _shade.css("opacity", args['shade'] ? args['shade'] : 0.3);
                    clearTimeout(stv);
                }, 0);

                $(window).on('resize', function() {
                    var n_dialog_w = $('body').width() * 0.7 > 1000 ? $('body').width() * 0.7 : 1000;
                    x_body.find('div.my_define_dialog').css('width', n_dialog_w + 'px');
                });

                _close.off('click').on('click', function() {
                    Util.SlideDialog.close();
                });
                if (opencbk) { opencbk(); }
            },
            close: function() {
                //close时会关掉所有滑出层
                var sdialogs = (window == top) ? $('body').find('#mainIframe').contents().find('div[defineds]') : $('div[defineds]');
                if (sdialogs.length > 0) {
                    //yes 关闭
                    sdialogs.each(function() {

                        var _t = $(this);
                        if (_t.hasClass('my_define_shade')) {
                            _t.css("opacity", "0").remove();
                        }
                        if (_t.hasClass('my_define_dialog')) {
                            var mainframe = $('body', window.parent.parent.document).find('#mainIframe');
                            //console.log($('body').find('#mainIframe'), mainframe);
                            _t.removeClass("from_right");
                            // if (mainframe.attr('last-phone')) {
                            //     mainframe.removeAttr('last-phone');
                            //     mainframe.removeAttr('last-starttime');
                            //     _t.find('iframe.my_define_iframe').contents().find('.dialog_slide_into').removeAttr('misscall');
                            //     _t.find('iframe.my_define_iframe').contents().find('.calling-status').html('&nbsp;&nbsp;&nbsp;&nbsp;数据连接中......');
                            // }
                        }
                        var stremove = setTimeout(function() {
                            _t.remove();
                            clearTimeout(stremove);
                        }, 500);
                    })
                }
            }
        },
        Feedback:{
            show: function(type, str, times, backurl){
                var _this = this;
                var autoClose = (typeof times !="undefined" && parseInt(times)>0)? true: false;
                var autoJump = (typeof backurl !="undefined" && backurl.indexOf('http')>-1)? true: false;
                var _class = "";
                switch(type){
                    case true:
                        _class = "theme-success";
                        break;
                    case false:
                        _class = "theme-failure";
                        break;
                    case "forbidden":
                        _class = "theme-forbidden";
                        break;
                    default:;            
                }
                _this.hide("");
                var $body = $('body');
                var $feed = $('<div class="feedback-layer"></div>');
                $feed.html('<div class="feedback-conbox">\
                    <div class="feedback-info">'+str+'<span class="auto"></span>\
                    '+ (autoJump?'<a href="'+backurl+'">立即跳转</a>':"") +'\
                    <i class="bcolor"></i>\
                    </div></div>');
                $body.append($feed);
                $feed.addClass(_class);
                if(autoClose){
                    _this.num = times;
                    $feed.find(".auto").html(times+"s后将自动"+(autoJump?"跳转":"关闭")+"！");
                    _this.feedtimer = setInterval(count, 1000);
                }
                function count(){
                    if(_this.num>1){
                        _this.num--;
                        $feed.find(".auto").html(_this.num+"s后将自动"+(autoJump?"跳转":"关闭")+"！");
                    }else{
                        clearInterval(_this.feedtimer);
                        _this.hide(autoJump?backurl:"");
                    }
                }
            },
            hide: function(backurl){
                var $body = $('body');
                $body.find('.feedback-layer').remove();
                (backurl!="")? (window.location.href = backurl):null;
            }
        },
        execInit: (function($){
            //easyui宽高自适应
            $(window).on('resize',function(){
                if($("div[resizeable='1']").length>0){
                    $("div[resizeable='1']").each(function(index, item){
                        $(item).triggerHandler('_resize');
                    })
                }
            });
            //关闭弹出层
            $(document).on('click', '.layui-layer-page button[role="btn-cancel"]', function(e) {
                e.preventDefault();
                $(this).parents('.layui-layer-page').find('.layui-layer-close')[0].click();
            });
        })($),
        easyloaderInit: function(){
            if($('input.time-spinner')){
                easyloader.theme = 'material-teal';
                using('timespinner', function () {
                    $('input.time-spinner').timespinner({height:'28px'});
                })
            }
        },
        SelectFile: {
            removeImgs: [],
            setPreviewInfo: function(msg){
                $('.preview-image-tips').html(msg);
            },
            removeFile: function(obj){
                var _box = $(obj).parents('.preview-box');
                $(obj).parents('.preview-image').remove();
                if(_box.find('.preview-image').length == 0){
                    _box.next('.upload-box').removeClass('disn'); 
                }
            },
            handleFiles: function(that, _files, _uploadUrl){
                var _this = this;
                var preview = $(".preview-box");
                var _multiple = that.attr('multiple');
                var fileList = typeof that.data('files') == "undefined"?{}: that.data('files');
                var oldLength = Object.keys(fileList).length;
                if(typeof _multiple=='undefined') { 
                    fileList = {};
                    preview.find('.preview-image').remove();
                    if(preview.find('.upload-box').length==0){
                        preview.html('');
                    }
                }

                if(_files.length == 0){ return false;}
                var maxSize = isNaN(parseInt(that.attr("size-max")))? 0: parseInt(that.attr("size-max"));
                _this.setPreviewInfo('');
                if(_files.length>5){
                    _this.setPreviewInfo('每次上传图片最多选中5张，已超出长度，请重新选择!');
                    return false;
                }

                for(var i=0; i<_files.length; i++){
                    var _file = _files[i];
                    var _name = _file.name; //名称
                    var _suffix = _file.type; //类型
                    var _size= _file.size; //大小

                    //限制类型jpg/png/jpeg/gif
                    var typeArr = ['jpg','png','jpeg','gif'];
                    if(typeArr.indexOf(_suffix.substr(6)) == -1){
                        // uploadTips('只能上传jpg/png/jpeg/gif文件!');
                        _this.setPreviewInfo('只能上传jpg/png/jpeg/gif格式的图片，不支持其他格式!');
                        continue;
                    }

                    //上传大小限制不超过2M
                    if(maxSize>0 && parseInt(_size)> maxSize*1024*1024){
                        _this.setPreviewInfo('文件大小超过2M的图片将不被上传!');
                        continue;
                    }

                    /* return image*/
                    var thumbImg = _this.getThumb(i-(-oldLength), _file);
                    var _cell = $('<div class="preview-image"></div>');
                    _cell.append(thumbImg);

                    /* return info*/
                    var sOutput = _this.setThumbSize(_size);
                    if(typeof _uploadUrl == 'undefined'){
                        _cell.append('<div class="preview-image-info">名称：'+_name+'<br/>大小：'+sOutput+'</div>');
                    }
                    _cell.append('<div class="preview-image-del"><i class="iconfont iconshanchu"></div>');

                    //_uploadUrl上传图片-》获取图片的oss地址
                    if(typeof _uploadUrl!='undefined' && _uploadUrl){
                        var formDt = new FormData();
                        formDt.append('file', _file);
                        _cell.append('<div class="preview-image-info" uploaded-value="url'+(i-(-oldLength))+'.png">已上传</div>');
                        // $.ajax({
                        //     async: false, 
                        //     type : "POST",
                        //     dataType: "json",
                        //     cache : false, 
                        //     url : _uploadUrl,
                        //     data : formDt,
                        //     processData: false, 
                        //     contentType: false,
                        //     success: function(data){
                        //         if (data['state'] == 'y'){
                        //             console.log(data);
                        //         }
                        //     }
                        // })
                    }

                    if(typeof _multiple=='undefined'){
                        if(preview.find('.upload-box').length==0){
                            preview.html(_cell);
                        }else{
                            preview.find('.upload-box').eq(0).before(_cell);
                        }
                        fileList[0] = _file;
                    }else{
                        if(preview.find('.upload-box').length==0){
                            preview.append(_cell);
                        }else{
                            preview.find('.upload-box').eq(0).before(_cell);
                        }
                        fileList[i-(-oldLength)] = _file;
                    }
                }
                that.val(''); //清空file的值
                that.data('files', fileList);
                if(typeof _multiple=='undefined'){
                    that.parents('.upload-box').addClass('disn');
                }

                preview.find('.preview-image-del').off('click').on('click',function(){
                    var key = $(this).parents('.preview-image').find('.pre-image')[0].key;
                    var fileList = that.data('files');
                    delete fileList[key];
                    that.data('files', fileList);
                    if(Object.keys(fileList).length == 0){
                        that.parents('.upload-box').removeClass('disn'); 
                    }
                    $(this).parents('.preview-image').remove();
                })
            },
            getThumb: function(key, _file){
                //显示缩略图
                var thumbImg = new Image();
                window.URL = window.URL || window.webkitURL;
                if(window.FileReader){
                    /*FileReader*/
                    var reader = new FileReader();
                    reader.onload = (function(tImg) { 
                        return function(e) { 
                            tImg.src = e.target.result;
                        }; 
                    })(thumbImg);
                    reader.readAsDataURL(_file);
                }else if(window.URL.createObjectURL){
                    /*URL.createObjectURL*/
                    thumbImg.src = window.URL.createObjectURL(_file);
                    thumbImg.onload = function() {
                        window.URL.revokeObjectURL(this.src);
                    }
                }
                thumbImg.classList.add("pre-image");
                thumbImg.file = _file;
                thumbImg.key = key;
                return thumbImg;
            },
            setThumbSize: function(_size){
                //显示图片大小
                var sOutput = _size + " B";
                var sizeSuff = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
                for (var n = 0, nApprox = _size / 1024; nApprox > 1; nApprox /= 1024, n++) {
                    sOutput = nApprox.toFixed(3) + " " + sizeSuff[n] + " (" + _size + " B)";
                }
                return sOutput;
            }
        },
        setTableHeadTips: function(arr){
            if(!arr){return;}
            if($('.table_box .hover-tooltip-cell').length>0){return;}
            $.each(arr,function(index,tip){
                if(index!=''){
                    $('.table_box .datagrid-header-row')
                        .find('td[field="'+index+'"] .datagrid-cell').css('position','relative')
                        .append('<a class="hover-tooltip-cell" href="javascript:void(0)" tips="'+tip+'">?</a>');
                }
            })
            easyloader.load('tooltip', function() {
                $('.hover-tooltip-cell').tooltip({
                    position: 'top',
                    content: function(){
                        return '<span class="tooltip-content-span">'+($(this).attr('tips'))+'</span>';
                    },
                    onShow: function(){
                        $(this).tooltip('tip').css({
                            backgroundColor: 'rgba(40, 48, 56, 0.8)',
                            borderColor: '#ffffff'
                        });
                    }
                });
            });
        },
        scrolling: function(s_box){
            $(s_box).find('.zs-box,.zs-list,.select-defined,.select-defined-content').removeClass('active').removeClass('active-top');
            $('body').find('.zs-list.zs-panel-list,.select-defined-content.relative-window-panel').removeClass('active').removeClass('active-top');
        }
    }
    return Util;
})(jQuery);